#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;//引出string实体

void test()
{
    string s1("hello");
    //从C风格字符串转换到了C++风格字符串string
    string s2 = ",world";
    cout << "s1 = " << s1 << endl;
    cout << "s2 = " << s2 << endl;

    cout << endl;
    //可以直接进行字符串的拼接，根本就不用考虑字符串长度的问题
    //也不用申请空间
    string s3 = s1 + s2;
    cout << "s3 = " << s3 << endl;

    cout << endl << endl;
    const char *pstr = s3.c_str();
    cout << "pstr = " << pstr << endl;

    //获取长度
    cout << endl;
    size_t len = s1.length();
    size_t len2 = s1.size();
    cout << "len = " << len << endl;
    cout << "len2 = " << len2 << endl;

    //遍历字符串
    cout  << endl;
    for(size_t idx = 0; idx != s1.size(); ++idx)
    {
        cout << s1[idx] << "  ";
    }
    cout << endl;

    cout << endl;
    string s4 = s3 + 'A';
    cout << "s4 = " << s4 << endl;

    cout << endl;
    string s5 = 'C' + s4;
    cout << "s5 = " << s5 << endl;

    cout << endl;
    string s6 = s5 + "------byby";
    cout << "s6 = " << s6 << endl;

    cout << endl;
    string s7 = s6.append("13678");
    cout << "s7 = " << s7 << endl;

    cout << endl;
    string s8 = s7.substr(1, 11);
    cout << "s8 = " << s8 << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

